package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.domain.Notification;
import com.tianyi.sfzy1.service.NotificationService;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("/notification")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;
    //插入通知
    @PostMapping("/insertNotification")
    public R insertNotification(Notification notification){
        int i = notificationService.insertNotification(notification);
        if (i>0){
            return R.ok();
        }
        return R.fail("插入失败");
    }

    //根据会员id查询通知
    @GetMapping("/findNotificationByMemberId")
    public R findNotificationByMemberId(int memberId){
        List<Notification> notifications = notificationService.findNotificationByMemberId(memberId);
        if (notifications!=null){
            return R.ok(notifications);
        }
        return R.fail("查询失败");
    }
}
